package com.bjsxt.controller;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.Menu;
import com.bjsxt.pojo.PageA;
import com.bjsxt.pojo.TreeA;
import com.bjsxt.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    //查询同步树形的菜单
    @RequestMapping("/findAllMenu3")
    public  List<TreeA>  findAllMenu3(){
        return  menuService.findAll3();
    }

    //查询角色下的菜单
    @RequestMapping("/findMoreMenu")
    public List<TreeA> findMoreMenu(@RequestParam(defaultValue = "0") Integer id, HttpSession session){
        Admin admin = (Admin) session.getAttribute("admin");
        return menuService.findMore(admin.getAid(),id);

    }

    //实现所有菜单的查询
    @RequestMapping("/findAllMenu")
    public PageA<Menu> findAllMenu(Integer page,Integer rows){
       return menuService.findAll(page, rows);
    }
    //异步树下角色菜单的实现

    @RequestMapping("/findMoreMenu2")
    public List<TreeA> findMoreMenu2(@RequestParam(defaultValue = "0") Integer id){
        return menuService.findAll2(id);
    }

    //添加菜单的实现
    @RequestMapping("/insertMenu")
    public Integer insertMenu(Menu menu){
        return menuService.insertMenu(menu);
    }

    //修改菜单的实现
    @RequestMapping("/changMenu")
    public Integer changMenu(Menu menu){
        return menuService.change(menu);
    }

    //删除菜单的实现
    @RequestMapping("/removeMenu")
    public  Integer removeMenu(Integer mid){
        return menuService.delete(mid);
    }


}
